<template>
	<view>
		<image mode="aspectFill" class="top-img" :src="products.image"></image>
		<view class="content">
			<view class="top">
				<view class="top-title">{{products.product_name}}</view>
				<view class="top-price">￥{{curPrice}}</view>
			</view>
			<view class="date">
				<view class="date-title"><text class="line">|</text>出发日期</view>
				<view class="date-select">
					<view v-for="(item,index) in prices" :key="index" @click="dateSelect(item.price, item.day)"
						class="date-item">
						<view>{{item.day}}</view>
						<view class="price">￥{{item.price}}</view>
					</view>
				</view>
			</view>
			<view class="date">
				<view class="date-title"><text class="line">|</text>说明</view>
				<view class="date-content">
					{{products.description}}
				</view>
			</view>
		</view>
		<footer-fixed-bar :barHeight="100">
			<view class="bottom-reserve-btns">
				<view class="content-btn">
					<view class="right">
						<button class="sell-btn" v-if="userType==1" @click="toFenxiao">分销</button>
						<button class="reserve-btn" @click="dateSelect(orderData.price,orderData.day)">立即预订</button>
					</view>
				</view>

			</view>
		</footer-fixed-bar>
	</view>
</template>

<script>
	import {
		apiUrl
	} from '@/api/base.js'
	import footerFixedBar from "@/components/footer-fixed-bar.vue";	
	export default {
		components: {		
			footerFixedBar
		},
		data() {
			return {				
				userType: uni.getStorageSync("userInfo").type,
				products: null,
				curPrice: 0,
				prices: [],
				orderData: {
					product_id: 0,
					day: 0,
					price: 0
				},
				dateRange: [],
				timeRange: [],
				buttonGroup: [{
					text: '分享',
					backgroundColor: '#ff0000',
					color: '#fff'
				}, {
					text: '立即预订',
					backgroundColor: '#ffa200',
					color: '#fff'
				}]
			}
		},
		onLoad(opt) {
			if(opt.id){
				this.orderData.product_id = opt.id	
			}			
			if(opt.scene){				
				let params = decodeURIComponent(opt.scene).split("&")				
				uni.setStorageSync('fxid', params[0]);
				this.orderData.product_id = params[1]
			}else{
				uni.removeStorageSync('fxid');
			}
		},
		onShow(){
			if (uni.getStorageSync("userInfo")) {
				this.userType = uni.getStorageSync("userInfo").type
			}
			
			//获取产品信息
			uni.request({
				url: apiUrl + "addons/car/product/detail",
				data: {
					id: this.orderData.product_id
				},
				method: "GET",
				success: (res) => {
					let data = res.data.data
					this.products = data
					//获取价格
					uni.request({
						url: apiUrl + "addons/car/product_price/getprices",
						data: {
							product_id: this.orderData.product_id
						},
						method: "GET",
						success: (res) => {
							this.prices = res.data.data
							this.orderData.day = this.prices[0].day
							this.orderData.price = this.prices[0].price
							this.curPrice = this.prices[0].price
						},
						fail: (res) => {
							console.log(res)
						}
					})
			
				},
				fail: (res) => {
					console.log(res)
				}
			
			})
		},
		methods: {
			toFenxiao() {
				uni.navigateTo({
					url: '/pages/fenxiao/invite?product_id=' + this.products.id
				});
			},
			dateSelect(price, day) {
				this.orderData.day = day
				this.orderData.price = price
				this.curPrice = price
				uni.navigateTo({
					url: '/pages/product/booking?product_name=' + this.products.product_name + '&product_id=' +
						this.orderData.product_id + '&day=' + this.orderData.day + '&price=' + this.orderData.price
				});
			},
			onClick(e) {
				console.log(e)
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
			}
		}
	}
</script>

<style lang="scss">
	.top-img {
		width: 100%;
		height: 400rpx;
	}

	.content {
		width: 100%;
		position: relative;
		top: -20rpx;
		background-color: #F7F7F7;
		border-radius: 20rpx 20rpx 0 0;
	}

	.top {
		border-radius: 20rpx 20rpx 0 0;
	}

	.top-title {
		border-radius: 20rpx 20rpx 0 0;
		padding: 20rpx;
		background-color: #FFFFFF;
	}

	.top-price {
		color: #DD524D;
		padding: 0 20rpx 20rpx 20rpx;
		background-color: #FFFFFF;
	}

	.date {
		background-color: #FFFFFF;
		margin-top: 10rpx;
	}

	.date-title {
		height: 60rpx;
		line-height: 60rpx;
		border-bottom: solid 2rpx #e1e1e1;
		padding: 20rpx;
	}

	.line {
		font-weight: bold;
		color: #4CD964;
		margin-right: 10rpx;
	}

	.date-buttons {
		padding: 20rpx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.date-btn {
		font-size: 24rpx;
	}

	.date-content {
		padding: 20rpx;
	}


	.bottom-reserve-btns {
		text-align: center;
		font-size: $uni-font-size-sm;

		.sold-out {
			height: 60rpx;
			line-height: 60rpx;
			background-color: rgba(0, 0, 0, .7);
			color: $uni-text-color-inverse;
		}

		.content-btn {
			@extend .justifyspace;
			height: 100rpx;
			box-shadow: 0px 5rpx 5rpx 0px rgba(11, 2, 5, 0.05);

			&.disabled {

				.sell-btn,
				.reserve-btn {
					color: #9d9d9d;

					&:after {
						display: none;
					}
				}

				.sell-btn {
					background-color: #e4e4e4;
				}

				.reserve-btn {
					background-color: #d0d0d0;
					border-radius: 0;
				}
			}
		}

		.left,
		.right {
			@extend .displayflex;
		}

		.contact-collect {
			@extend .directionColumnJustify;
			width: 115rpx;
			color: #666;

			.iconfont {
				margin-bottom: 3rpx;
			}

			&.on {
				.iconfont {
					color: $uni-text-color-price;
				}
			}
		}

		.right {
			@extend .flex1;
		}

		.sell-btn,
		.reserve-btn {
			@extend .alignJustify;
			@extend .flex1;
			color: $uni-text-color-inverse;

			&:after {
				display: none;
			}
		}

		.sell-btn {
			background-color: #ffaa06;
			border-radius: 0;
		}

		.reserve-btn {
			background-color: $uni-bg-color-primary;
			border-radius: 0;
		}

	}

	.date-select {
		display: flex;
		justify-content: center;
		margin-bottom: 44rpx;
		font-family: "Arial";
		font-size: $uni-font-size-sm;
		padding: 10rpx 0;
	}

	.date-item {
		box-sizing: border-box;
		@extend .directionColumnJustify;
		align-items: center;
		width: 170rpx;
		height: 88rpx;
		margin-left: 13rpx;
		border: 2rpx solid #e5e5e5;
		border-radius: 10rpx;

		&:first-child {
			margin-left: 0;
		}

		.price {
			margin-top: 6rpx;
			font-size: $uni-font-size-mini;
			color: $uni-text-color-price;
		}

		&.on {
			background-color: #f7fff9;
			border-color: $uni-color-primary;
		}
	}
</style>
